<?php

// Inputs: Provide a full path URL.
// The function determines if the URL is of the appropriate type for us to work with and delivers the modification date if it is.
// Outputs: String containing the time the URL was last modified, or 0 if the format does not apply to us.
function isValidLink($url)
{
	// request: 'HEAD $url HTTP/1.1'
	$url = get_headers($url);
	$lastModified;
	$isLink = false;

	// Headers being read one at a time.
	foreach ($url as $link) 
	{
		// If the content Type is set to text/html, set the flag to true;
		if($link == 'Content-Type: text/html')
		{
			$isLink = true;
		}
		// If this is the Last Modified flag, save it because we might have to return it if it is a text/html page.
		if(substr($link,0,14) == 'Last-Modified:')
		{
			$lastModified = substr($link,15);
		}
	}
	
	// Return the time it was last modified, if the flag is set to true;
	if($isLink)
	{
		return $lastModified;
	}
	else
	{
		return 0;
	}
}

?>